/*
 * @Author: your name
 * @Date: 2021-08-03 20:18:57
 * @LastEditTime: 2021-08-13 17:30:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \niushop\src\store\index.js
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    badge:"",
    shoplist:[],
    obj:{},
    list:[{
      name:"童装玩具",
      src:require('../assets/images/wanju.jpg')
    },{
        name:"珠宝首饰",
        src:require('../assets/images/zhubao.jpg')
    },
    {
        name:"大家电",
      src:require('../assets/images/shuji.jpg')
    },
    {
        name:"男装",
      src:require('../assets/images/nanzhuang.jpg')
    },
    {
        name:"女装",
        src:require('../assets/images/nvzhuang.jpg')
    },
    {
        name:"食品酒水",
        src:require('../assets/images/shipin.jpg')
    },
    {
        name:"邮币乐器",
      src:require('../assets/images/yueqi.jpg')
    },
    {
        name:"钟表眼镜",
        src:require('../assets/images/yanjin.jpg')
    },
    ],
    cartlist:[]
  },
  mutations: {
    add (state) {
      state.badge++
    },
    changelist(state,e){
        state.shoplist.push(e)
    },
  //  coutlist(state) { 
  //     let clist=JSON.parse(JSON.stringify(state.shoplist))
  //     console.log(state);
  //     for(let i=0;i<clist.length;i++){
  //       if(!state.obj[JSON.parse(JSON.stringify(clist[i]))]){
  //         state.obj[JSON.parse(JSON.stringify(clist[i]))]=1;   //数量加一
  //       }else{
  //         state.obj[JSON.parse(JSON.stringify(clist[i]))]++;   // 为对象增加一个属性并赋初值1
  //       }
  //     }
  //     return state.obj;
  //   }
    changeCart(state ,res){
        state.cartlist=res.data
    }
  },
  actions: {
   async qjCart({commit}){
     console.log(23);
      let res= await this.$http({
         method:"get",
         path:"/cart/list",
         params:{
           id:window.sessionStorage.id
         }
       })
      commit("changeCart",res)

   },
  },
  modules: {
  }
})
